package com.cloud.point.designPattern.builder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Component;

/**
 * IMenuImpl
 *
 * @author 24373
 * @version 1.0
 * @date 2025-06-08 18:40
 */
@Component
public class IMenuImpl implements IMenu {

    List<Matter> menuList = new ArrayList<>();
    // 装修价格
    private BigDecimal price = BigDecimal.ZERO;
    // 面积
    private BigDecimal area;
    // 品牌
    private String grade;

    // Spring 会优先使用无参构造函数来创建对象，而不是尝试使用带参数的构造函数进行依赖注入
    public IMenuImpl() {
    }

    public IMenuImpl(BigDecimal area, String grade) {
        this.area = area;
        this.grade = grade;
    }

    @Override
    public IMenu appendCeiling(Matter matter) {
        menuList.add(matter);
        price = price.add(area.multiply(new BigDecimal("1.7")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendCoat(Matter matter) {
        menuList.add(matter);
        price = price.add(area.multiply(new BigDecimal("1.3")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendTile(Matter matter) {
        menuList.add(matter);
        price = price.add(area.multiply(new BigDecimal("1.1")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendWood(Matter matter) {
        menuList.add(matter);
        price = price.add(area.multiply(new BigDecimal("0.8")).multiply(matter.price()));
        return this;
    }

    @Override
    public String getDetail() {
        StringBuilder detail = new StringBuilder("\r\n-------------------------------------------------------\r\n" +
                "装修清单" + "\r\n" +
                "套餐等级：" + grade + "\r\n" +
                "套餐价格：" + price.setScale(2, BigDecimal.ROUND_HALF_UP) + " 元\r\n" +
                "房屋面积：" + area.doubleValue() + " 平米\r\n" +
                "材料清单：\r\n");

        for (Matter data : menuList) {
            detail.append(data.scene()).append("：").append(data.brand()).append("、").append(data.model()).append("、平米价格：").append(data.price()).append(" 元。\n");
        }
        return detail.toString();
    }

}
